﻿using System.Collections.Generic;
using System.Linq;

namespace System.Modules.SharePoint.Contracts.DTO
{
    /// <summary>
    /// SP Field Collection
    /// </summary>
    public class SPQueryFieldsCollection : SPQueryViewFieldsCollection
    {
        #region Constructor
        /// <summary>
        /// Default Constructor
        /// </summary>
        public SPQueryFieldsCollection() {}

        /// <summary>
        /// Default Constructor
        /// </summary>
        /// <param name="items"></param>
        public SPQueryFieldsCollection(IEnumerable<SPQueryFieldRef> items) : base(items.Cast<SPQueryViewField>().ToList()) { }
        #endregion

        #region Methods
        /// <summary>
        /// Contains
        /// </summary>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        public bool Contains(string fieldName)
        {
            return Items.OfType<SPQueryFieldRef>().Any(match => match.FieldName.Equals(fieldName, StringComparison.CurrentCultureIgnoreCase));
        }

        /// <summary>
        /// Remove
        /// </summary>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        public bool Remove(string fieldName)
        {
            return Items.OfType<SPQueryFieldRef>().ToList().RemoveAll(item => item.FieldName.Equals(fieldName, StringComparison.CurrentCultureIgnoreCase)) > 0;
        }
        #endregion
    }
}
